<?php $this->pageTitle = 'Payable Item ' . '#' . $payableItem->id; ?>
<?php
$this->breadcrumbs = array(
	'Commissions Payable' => array('/commissionPayable/index'),
	'Payable Item #' . $payableItem->id
);
?>
<div class="main-title no-border clearfix">
	<h1 class="float-left">Payable Item #<?php echo $payableItem->id; ?></h1>
	<?php if ($payableItem->deleted == 0): ?>
		<div class="controls float-right">
			<a class="link-button with-icon" id="cancel" href="#">
				<img src="/images/icons/fugue/cross-circle.png" />
				Cancel Payable Item
			</a>
		</div>
	<?php endif; ?>
</div>
<div class="flat_area">
	<div class="">
		<div id="ps-payment-view" class="relative">
			<div id="payable-item-info" class="">
				<div class="grid_11">
					<div class="section">
						<div class="block">
							<h2>Payable Item Information</h2>
							<?php
							$this->widget('zii.widgets.CDetailView', array(
								'data' => $payableItem,
								'nullDisplay' => '-',
								'attributes' => array(
									array(
										'label' => 'Payee Name',
										'value' => $payableItem->getPayeeName(),
									),
									array(
										'label' => 'Commission Type',
										'value' => $payableItem->getCommType() ? $payableItem->getCommType() : 'Adjustment',
									),
									'description',
									array(
										'label' => 'Transaction No',
										'value' => '#' . $payableItem->propertyCase->case_number
									),
									array(
										'label' => 'Transaction Address',
										'value' => $payableItem->propertyCase->property->prop_address_formatted
									),
									array(
										'label' => 'Receipt No',
										'value' => $payableItem->payment->payment_number ? '#' . $payableItem->payment->payment_number : '-',
									),
									array(
										'label' => 'Created On',
										'value' => Yii::app()->dateFormatter->formatDateTime(strtotime($payableItem->create_time), "short", null),
									),
									array(
										'label' => 'Created By',
										'value' => $payableItem->createdByUser->name,
									),
									array(
										'label' => 'Creation Method',
										'value' => $payableItem->is_manual ? 'Generated from commission structures' : 'Manual',
									),
								),
							));
							?>
						</div>
					</div>
				</div>
				<div class="grid_5">
					<div class="section highlighted">
						<div class="block">
							<?php
							$this->widget('zii.widgets.CDetailView', array(
								'data' => $payableItem,
								'htmlOptions' => array('class' => 'summary-table'),
								'attributes' => array(
									array(
										'label' => 'Payable Item No',
										'value' => '#' . $payableItem->id
									),
									array(
										'label' => 'Status',
										'type' => 'raw',
										'value' => $payableItem->getStatus()
									),
									array(
										'label' => $payableItem->getTotalAdjustments() <> 0 ? 'Amount (Unadjusted)' : 'Amount',
										'value' => Yii::app()->numberFormatter->formatCurrency($payableItem->net_amount, $payableItem->payment->currency_code ? $payableItem->payment->currency_code : "$")
									),
								)
							));
							?>
						</div>
					</div>
				</div>
				<?php if (!$payableItem->isAdjustmentCommType()): ?>
					<div id="related-adjustments" class="grid_16">
						<div class="section">
							<div class="block">
								<div class="clearfix">
									<h2 class="float-left">Related Adjustments</h2> 
									<a id="add-adjustment" class="link-button with-icon" href="<?php
				echo $this->createUrl('commissionPayable/create', array(
					'type' => PayableItem::COMM_TYPE_ADJUSTMENT,
					'id' => $payableItem->property_case_id,
					'parentId' => $payableItem->id
				));
					?> ">
										<img src="/images/icons/fugue/plus.png" />
										Add Adjustment
									</a>
								</div>
								<?php
								$this->widget('PsGridView', array(
									'id' => 'payment_application_grid',
									'dataProvider' => PayableItem::model()->search($payableItem->id),
									'template' => '{pager}{items}',
									'pagesizeCssClass' => 'pager-pagesize',
									'itemsCssClass' => 'items clear',
									'emptyText' => 'No adjustments found.',
									'selectableRows' => 0,
									'htmlOptions' => array(
										'class' => 'grid-view grey',
									),
									'columns' => array(
										array(
											'header' => '#',
											'name' => 'id',
											'type' => 'raw',
											'value' => 'CHtml::link("#" . $data->id, array("view", "id" => $data->id), array("class" => "blue link"))',
											'headerHtmlOptions' => array(
												'width' => 50
											),
										),
										array(
											'header' => 'Date',
											'name' => 'create_time',
											'value' => 'Yii::app()->dateFormatter->formatDateTime(strtotime($data->create_time), "short", null)',
											'headerHtmlOptions' => array(
												'width' => 80
											)
										),
										array(
											'header' => 'Payee Name',
											'name' => 'party.user.name',
											'type' => 'raw',
											'value' => '$data->comm_type != PayableItem::COMM_TYPE_EXTERNAL ? CHtml::link($data->getPayeeName(), array("/manage/users/view", "id" => $data->payeeParty->getUser()->id), array("class" => "blue link")) : $data->getPayeeName()',
											'headerHtmlOptions' => array(
												'width' => 160
											),
											'htmlOptions' => array('class' => 'no-wrap')
										),
										array(
											'header' => 'Description',
											'value' => '$data->description ? $data->description : "-"',
											'headerHtmlOptions' => array(
												'width' => 260
											),
											'htmlOptions' => array(
												'class' => 'no-wrap',
											)
										),
										array(
											'header' => 'Receipt No.',
											'name' => 'payment.payment_number',
											'type' => 'raw',
											'value' => 'CHtml::link((isset($data->payment))?"#".$data->payment->payment_number:"", array("receipt/view", "id" => $data->payment->id), array("class" => "blue link"))',
											'headerHtmlOptions' => array(
												'width' => 80
											)
										),
										array(
											'header' => 'Category',
											'name' => 'comm_type',
											'value' => '$data->getCommTypeFormatted()',
											'htmlOptions' => array('class' => ''),
											'headerHtmlOptions' => array(
												'width' => 70
											),
											'footer' => 'Adjusted Amount',
											'footerHtmlOptions' => array(
												'class' => 'bold',
											),
										),
										array(
											'header' => 'Amount',
											'name' => 'net_amount',
											'type' => 'raw',
											'value' => 'Yii::app()->numberFormatter->formatCurrency($data->getAdjustedAmount(), $data->payment->currency_code ? $data->payment->currency_code:"$")',
											'htmlOptions' => array(
												'class' => 'align-right',
												'width' => 100
											),
											'footer' => Yii::app()->numberFormatter->formatCurrency($payableItem->getAdjustedAmount(), $payableItem->payment->currency_code ? $payableItem->payment->currency_code : "$"),
											'footerHtmlOptions' => array(
												'class' => 'align-right',
												'width' => 100,
												'style' => 'padding-right: 10px;'
											),
											'headerHtmlOptions' => array(
												'class' => 'align-right',
												'width' => 100
											)
										),
									)
								));
								?>
							</div>

							<div class="block">


							</div>

						</div>
						<?php // if ($payableItem->getTotalAdjustments() <> 0):   ?>
						<!--						<div id="adjusted-balance">
													<div class="section highlighted">
														<div class="block">
															<div class="float-left">
																<strong>Net Adjusted Amount</strong>
															</div>
															<div class="float-right">
																<strong>//<?php echo Yii::app()->numberFormatter->formatCurrency($payableItem->getAdjustedAmount(), $payableItem->payment->currency_code ? $payableItem->payment->currency_code : "$"); ?></strong>
															</div>
														</div>
													</div>
												</div>-->
						<?php // endif;   ?>
					</div>
				<?php endif; ?>
			</div>
		</div>
	</div>
</div>


